package com.asdan.seededu.front.service.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.asdan.seededu.entity.security.SubProject;
import com.asdan.seededu.entity.security.SubProjectStep;
import com.asdan.seededu.entity.security.User;
import com.asdan.seededu.front.service.ISWEEPService;
import com.asdan.seededu.service.impl.UtilImpl;
import com.asdan.seededu.util.DatabaseAccess;
import com.demo2do.core.utils.JsonUtils;

public class ISWEEPServiceImp extends UtilImpl implements ISWEEPService {
	
public boolean  CreateUserData(int uid,int spid,int stepid){
		
	DatabaseAccess databaseAccess = new DatabaseAccess(false);
	Connection cn = null;
	PreparedStatement pstmt=null;
	boolean temp=true;
		String sql="insert into userdata(uid, stepid , stepstatus, data, spid ) values(?,?,?,?,?)";
	try{
		cn = databaseAccess.getConn();
		pstmt = cn.prepareStatement(sql);
		pstmt.setInt(1, uid) ;
		pstmt.setInt(2, stepid) ;
		pstmt.setInt(3, 1) ;
		pstmt.setString(4, "") ;
		pstmt.setInt(5, spid);
	    pstmt.execute();
		
	}catch(Exception e){
		e.printStackTrace();
		System.out.println(e.getMessage());
		temp=false;
	}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
		try{
			pstmt.close();
			cn.close();
			databaseAccess.close() ;
		}catch(Exception ex){
				pstmt = null ;
				cn = null ;
				temp=false;

		}
	}
	return temp;
	}
	
	

	
	//获取流程
	public List<SubProjectStep> getLiucheng(int pid){
		   DatabaseAccess databaseAccess = new DatabaseAccess(false);
			Connection cn = null;
			PreparedStatement pstmt=null;
			ResultSet rs=null;
			SubProjectStep subprostep=null;
			List<SubProjectStep> list=new ArrayList<SubProjectStep>();
			String sql="select * from subprojectstep where  spid=?";
			System.out.println("spid:"+pid);
			try{
				
				cn = databaseAccess.getConn();
				pstmt = cn.prepareStatement(sql);
				pstmt.setInt(1, pid) ;
				//pstmt.setInt(1, pid) ;
				rs=pstmt.executeQuery();
				while(rs.next()){
					subprostep = new SubProjectStep() ;
			        subprostep.setStepid(rs.getInt("stepid"));
			        subprostep.setSpid(rs.getInt("spid"));
			        subprostep.setName(rs.getString("name"));
			        subprostep.setStepName(rs.getString("stepName"));
			        
			        subprostep.setAttachment1name(rs.getString("attachment1name"));
			        subprostep.setAttachment1address(rs.getString("attachment1address"));
			        subprostep.setAttachment2name(rs.getString("attachment2name"));
			        subprostep.setAttachment2address(rs.getString("attachment2address"));
			        subprostep.setAttachment3name(rs.getString("attachment3name"));
			        subprostep.setAttachment3address(rs.getString("attachment3address"));
			        subprostep.setAttachment4name(rs.getString("attachment4name"));
			        subprostep.setAttachment4address(rs.getString("attachment4address"));
			        subprostep.setAttachment5name(rs.getString("attachment5name"));
			        subprostep.setAttachment5address(rs.getString("attachment5address"));
					
			        list.add(subprostep);
			        
			        System.out.println("stepName:"+rs.getString("name"));
				}
				
			}catch(Exception e){
				e.printStackTrace();
				System.out.println(e.getMessage());
				
			}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
				try{
					pstmt.close();
					cn.close();
					databaseAccess.close() ;
				}catch(Exception ex){
						pstmt = null ;
						cn = null ;
				}	
			}
			return list;
	   }

	public boolean isExist(int uid,int pid,int stepid){
		DatabaseAccess databaseAccess = new DatabaseAccess(false);
		Connection cn = null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		boolean flag=false;
		String sql="select * from userdata where uid=? and spid=? and stepid=?";
		try{
			
			cn = databaseAccess.getConn();
			pstmt = cn.prepareStatement(sql);
			pstmt.setInt(1, uid) ;
			pstmt.setInt(2, pid) ;
			pstmt.setInt(3, stepid) ;
			 rs=pstmt.executeQuery();
			if(rs.next()){
		       flag=true;
			}
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			
		}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
			try{
				pstmt.close();
				cn.close();
				databaseAccess.close() ;
			}catch(Exception ex){
					pstmt = null ;
					cn = null ;
			}	
		}
		return flag;
	}
	public User getData(int uid,int pid){
		DatabaseAccess databaseAccess = new DatabaseAccess(false);
		Connection cn = null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		User user=new User();
		String sql="select data from userdata where uid=? and spid=? ";
		try{
			
			cn = databaseAccess.getConn();
			pstmt = cn.prepareStatement(sql);
			pstmt.setInt(1, uid) ;
			pstmt.setInt(2, pid) ;
			
			 rs=pstmt.executeQuery();
			if(rs.next()){
				if(rs.getString("data") == null || "".equals(rs.getString("data")) ){
					user=new User();
				}else{
					user=JsonUtils.parse(rs.getString("data"), User.class);
				}
			}
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			
		}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
			try{
				pstmt.close();
				cn.close();
				databaseAccess.close() ;
			}catch(Exception ex){
					pstmt = null ;
					cn = null ;
			}	
		}
		return user;
	}
	public Boolean HasData(int uid,int pid){
		DatabaseAccess databaseAccess = new DatabaseAccess(false);
		Connection cn = null;
		PreparedStatement pstmt=null;
		ResultSet rs=null;
		String sql="select data from userdata where uid=? and spid=? ";
		try{
			System.out.println("111111");
			cn = databaseAccess.getConn();
			pstmt = cn.prepareStatement(sql);
			pstmt.setInt(1, uid) ;
			pstmt.setInt(2, pid) ;
			
			 rs=pstmt.executeQuery();
			if(rs.next()){
				System.out.println("22222");
				if(rs.getString("data")!=null && (!rs.getString("data").equals("") ) )
				{
					System.out.println("33333");
					return true;
				}
			}
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
			
		}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
			try{
				pstmt.close();
				cn.close();
				databaseAccess.close() ;
			}catch(Exception ex){
					pstmt = null ;
					cn = null ;
			}	
		}
		return false;
	}
	
	public User getInfo(int uid,int spid){
		DatabaseAccess databaseAccess = new DatabaseAccess(false);
		Connection cn = null;
		PreparedStatement pstmt=null;
		ResultSet rs = null;
		User user = null ;
		String sql = "select orders.information as information,orders.price as price"+
		" from orders,order_reply where orders.oid=order_reply.oid "+
		"and order_reply.is_success='T' and orders.suid=? and orders.spid=?";
		System.out.println(sql);	
		try{
			cn = databaseAccess.getConn();
			pstmt = cn.prepareStatement(sql);
			pstmt.setInt(1, uid) ;
			pstmt.setInt(2, spid) ;
			rs = pstmt.executeQuery();
			int p=0;
			while(rs.next()){
				user= new User();
				System.out.println(rs.getString("information"));
				user=JsonUtils.parse(rs.getString("information"), User.class);
				p=rs.getInt("price");
				if(p>=2800){				//根据总价格判断是否住宿
				user.setIfhotel("1");
				}
				else{
					user.setIfhotel("0");
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e.getMessage());
		}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
			try{
				pstmt.close();
				cn.close();
				databaseAccess.close() ;
			}catch(Exception ex){
					pstmt = null ;
					cn = null ;
			}
		}
		return user ;
	}
	
		public int getCurrentStepid(int uid,int pid){
			DatabaseAccess databaseAccess = new DatabaseAccess(false);
			Connection cn = null;
			PreparedStatement pstmt=null;
			ResultSet rs=null;
			
			int stepid=0;
			String sql="select stepid from userdata where uid=? and spid=? ";
			try{
				
				cn = databaseAccess.getConn();
				pstmt = cn.prepareStatement(sql);
				pstmt.setInt(1, uid) ;
				pstmt.setInt(2, pid) ;
				
				 rs=pstmt.executeQuery();
				if(rs.next()){
					stepid=rs.getInt("stepid");
				}
				
			}catch(Exception e){
				e.printStackTrace();
				System.out.println(e.getMessage());
				
			}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
				try{
					pstmt.close();
					cn.close();
					databaseAccess.close() ;
				}catch(Exception ex){
						pstmt = null ;
						cn = null ;
				}	
			}
			return stepid;
		}
		public String prepare(String functionname, String uid, String spid,
				String stepid) {
			//打印备注
			System.out.println("in function"+functionname+"():");	
			System.out.println("uid:"+uid);
			System.out.println("stepid:"+stepid);
			System.out.println("spid:"+spid);
			//合法性判断
			if(uid==null || "".equals(uid)){
				return "notlogin";
			}
			if(spid==null || "".equals(spid)){
				return "参数输入有误！";
			}
			if(stepid==null || "".equals(stepid)){
				return "参数输入有误！";
			}
			return "OK";
		}
		public void printlog(String functionname, String uid, String spid,
				String stepid, List<SubProjectStep> list) {
			// TODO Auto-generated method stub
			System.out.println("changed:");
			System.out.println("stepid"+stepid);
			System.out.println("uid"+uid);
			System.out.println("spid"+spid);
			System.out.println("steplist"+list);
			System.out.println("function "+functionname+" finished");	
		}
		public boolean HasOrder(int uid,int spid) {
			DatabaseAccess databaseAccess = new DatabaseAccess(false);
			Connection cn = null;
			PreparedStatement pstmt=null;
			ResultSet rs=null;
			
			boolean temp=false;
			String sql="select oid from v_user_subproject_order where uid=? and spid=? and orderdelete!=1 ";
			try{
				
				cn = databaseAccess.getConn();
				pstmt = cn.prepareStatement(sql);
				pstmt.setInt(1, uid) ;
				pstmt.setInt(2, spid) ;
				
				 rs=pstmt.executeQuery();
				if(rs.next()){
					temp=true;
				}
				
			}catch(Exception e){
				e.printStackTrace();
				System.out.println(e.getMessage());
				
			}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
				try{
					pstmt.close();
					cn.close();
					databaseAccess.close() ;
				}catch(Exception ex){
						pstmt = null ;
						cn = null ;
				}	
			}
			return temp;
		}

		public boolean saveInfo( int stepid,int uid,int pid, String name, String sex,
				String firstname, String lastname, String birthday,String idCard,
				String schoolname, String grade, String email, String phone,
				String qq, String address, String postcode, String fathername,
				String fatheremail,String fatherphone, String mothername,String motherphone, String motheremail,String isbookhotel) {
	     
			System.out.println(stepid+"stepidwyefs");
			
			DatabaseAccess databaseAccess = new DatabaseAccess(false);
			Connection cn = null;
			PreparedStatement pstmt=null;
			boolean temp=true;
		
			
			System.out.println("heheuid:"+uid);
			System.out.println("hehespid:"+pid);
			System.out.println("hehe:"+schoolname);
			String data=null;
			User user=this.getData(uid, pid);
			System.out.println(user);
			
			user.setUid(uid) ;
			user.setName(name);
			user.setSex(sex);
			user.setFirstName(firstname);
			user.setLastName(lastname);
			user.setGrade(grade);
			user.setSchoolname(schoolname);
			user.setBirthday(birthday);
			user.setIdCard(idCard);
			user.setPostCode(postcode);
			user.setAddress(address);
			user.setCellPhone(phone);
			user.setQQ(qq);
			user.setEmail(email);
			user.setFatherName(fathername);
			user.setMotherName(mothername);
			user.setFatherEmail(fatheremail);
			user.setFatherPhone(fatherphone);
			user.setMotherEmail(motheremail);
			user.setMotherPhone(motherphone);
			user.setIfhotel(isbookhotel);
			
			
			data=JsonUtils.toJsonString(user);
			System.out.println(data+"data++++++++++");
			
			try{
				
				cn = databaseAccess.getConn();
				
					String hql="update userdata set  stepid=?, stepstatus=?, data=?  where uid=? and spid=?";
					pstmt = cn.prepareStatement(hql);
					pstmt.setInt(1, stepid) ;
					pstmt.setInt(2, 1) ;
					pstmt.setString(3, data) ;
					pstmt.setInt(4, uid);
					pstmt.setInt(5, pid);
				System.out.println(hql);
			    pstmt.execute();
				temp=true;
			}catch(Exception e){
				e.printStackTrace();
				System.out.println(e.getMessage());
				temp=false;
			}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
				try{
					pstmt.close();
					cn.close();
					databaseAccess.close() ;
				}catch(Exception ex){
						pstmt = null ;
						cn = null ;
						temp=false;

				}
			}
			return temp;
			
		
		}


		public boolean outprepare(int stepid,int uid, int pid,String hb_cc, String datapicker,
				String arriveAddress, String jiaotongxinxi, String paifangxinxi) {
			
			DatabaseAccess databaseAccess = new DatabaseAccess(false);
			Connection cn = null;
			PreparedStatement pstmt=null;
			boolean temp=true;
			User user=this.getData(uid, pid);
			user.setHb_cc(hb_cc);
			user.setJtxxbz(jiaotongxinxi);
			user.setPfqk(paifangxinxi);
			user.setArriveaddress(arriveAddress);
			user.setArrivetime(datapicker);
			String data=JsonUtils.toJsonString(JSONArray.toJSON(user));
			
			
			try{
				String sql="update userdata set stepid=? , data=? where uid=? and spid=?";
				cn = databaseAccess.getConn();
				pstmt = cn.prepareStatement(sql);
				pstmt.setInt(1, stepid+1) ;
				pstmt.setString(2, data) ;
				pstmt.setInt(3, uid) ;
				pstmt.setInt(4, pid);
				
			    pstmt.execute();
				temp=true;
			}catch(Exception e){
				e.printStackTrace();
				System.out.println(e.getMessage());
				temp=false;
			}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
				try{
					pstmt.close();
					cn.close();
					databaseAccess.close() ;
				}catch(Exception ex){
						pstmt = null ;
						cn = null ;
						temp=false;

				}
			}
			return temp;
			
		}
	//保存反馈评价
		public boolean saveFeedback(int stepid,int uid, int pid, String fkpjbz) {
			
			DatabaseAccess databaseAccess = new DatabaseAccess(false);
			Connection cn = null;
			PreparedStatement pstmt=null;
			boolean temp=true;
			User user=this.getData(uid, pid);
			
			user.setFkpjbz(fkpjbz);
			
			String data=JsonUtils.toJsonString(JSONArray.toJSON(user));
			
			
			try{
				String sql="update userdata set stepid=? , data=? where uid=? and spid=?";
				cn = databaseAccess.getConn();
				pstmt = cn.prepareStatement(sql);
				pstmt.setInt(1, stepid+1) ;
				pstmt.setString(2, data) ;
				pstmt.setInt(3, uid) ;
				pstmt.setInt(4, pid);
				
			    pstmt.execute();
				temp=true;
			}catch(Exception e){
				e.printStackTrace();
				System.out.println(e.getMessage());
				temp=false;
			}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
				try{
					pstmt.close();
					cn.close();
					databaseAccess.close() ;
				}catch(Exception ex){
						pstmt = null ;
						cn = null ;
						temp=false;

				}
			}
			return temp;
			
		}
		//保存获取结果
			public boolean saveResult(int stepid,int uid, int pid, String hjqk,String hqjgbz) {
				
				DatabaseAccess databaseAccess = new DatabaseAccess(false);
				Connection cn = null;
				PreparedStatement pstmt=null;
				boolean temp=true;
				User user=this.getData(uid, pid);
				
				user.setHjqk(hjqk);
				user.setHqjgbz(hqjgbz);
				
				String data=JsonUtils.toJsonString(JSONArray.toJSON(user));
				
				
				try{
					String sql="update userdata set stepid=? , data=? where uid=? and spid=?";
					cn = databaseAccess.getConn();
					pstmt = cn.prepareStatement(sql);
					pstmt.setInt(1, stepid) ;
					pstmt.setString(2, data) ;
					pstmt.setInt(3, uid) ;
					pstmt.setInt(4, pid);
					
				    pstmt.execute();
					temp=true;
				}catch(Exception e){
					e.printStackTrace();
					System.out.println(e.getMessage());
					temp=false;
				}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
					try{
						pstmt.close();
						cn.close();
						databaseAccess.close() ;
					}catch(Exception ex){
							pstmt = null ;
							cn = null ;
							temp=false;

					}
				}
				return temp;
				
			}


			public SubProject  getNewISWEEP(){
				
				DatabaseAccess databaseAccess = new DatabaseAccess(false);
				Connection cn = null;
				PreparedStatement pstmt=null;
				ResultSet rs=null;
				SubProject sp =null ;
				//List list=new ArrayList();
		 		String sql="select spid ,fpid ,name,pcreattime ,starttime ,endtime , price ,uid ,description   from subproject where fpid = 12 order by spid desc limit 1 ";
				try{
					cn = databaseAccess.getConn();
					pstmt = cn.prepareStatement(sql);
					rs=pstmt.executeQuery();
					rs.next() ;
					 sp = new SubProject()   ;
					sp.setSpid(rs.getInt("spid")) ;
					sp.setFpid(rs.getInt("fpid")) ;
					sp.setName(rs.getString("name")) ;
					sp.setPcreatTime(rs.getString("pcreattime")) ;
					sp.setStartTime(rs.getString("starttime")) ;
					sp.setEndTime(rs.getString("endtime")) ;
					sp.setPrice(rs.getDouble("price")) ;
					sp.setTuid(rs.getString("uid")) ;
					sp.setProjectinformation(rs.getString("description")) ;
					}catch(Exception e){
					e.printStackTrace();
					System.out.println(e.getMessage());
				}finally{                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
					try{
						pstmt.close();
						cn.close();
						databaseAccess.close() ;
					}catch(Exception ex){
							pstmt = null ;
							cn = null ;
							
					}
				}
				return sp ;
			}

			
			
}

	
